package com.tobby.camel.camelinaction.chapter3.order;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;

public class PurchaseOrderXstreamTest extends CamelSpringTestSupport {

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext(
				"com/tobby/camel/camelinaction/chapter3/order/order-xstream.xml");
	}

	@Test
	public void testXstream() throws InterruptedException {
		XStream stream = new XStream();
		stream.addPermission(AnyTypePermission.ANY);
		MockEndpoint endpoint = getMockEndpoint("mock:order");
		endpoint.expectedMessageCount(1);
		endpoint.message(0).body().isInstanceOf(PurchaseOrder.class);

		PurchaseOrder order = new PurchaseOrder();
		order.setName("Camel in action");
		order.setPrice(4995);
		order.setAmount(1);
		template.sendBody("direct:order", order);

		assertMockEndpointsSatisfied();
	}

}
